package response

import (
	"net/http"

	"gitee.com/liuxiaowei123/vblog-1.1/exception"
	"github.com/gin-gonic/gin"
)

func Success(c *gin.Context, data any) {
	c.JSON(http.StatusOK, data)
}

func Failed(c *gin.Context, err error) {
	defer c.Abort()
	var e *exception.Apiexcetion
	if v, ok := err.(*exception.Apiexcetion); ok {
		e = v
	} else {
		e = exception.NewApiexcetion(http.StatusInternalServerError, err.Error())
		e.Httpcode = http.StatusInternalServerError
	}
	c.JSON(e.Httpcode, e)
}
